package com.caimiao.miao.library.database;

import java.util.HashMap;
import java.util.Map;

public class DBHelperFactory {
    private static Map<String, Object> stack = new HashMap<>();

    public static <T> T getDBHelper(Class<T> tClass) {
        T instance = null;
        try {
            if (stack.containsKey(tClass.getName())) {
                instance = (T) stack.get(tClass.getName());
            } else {
                instance = tClass.newInstance();
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
        if (instance != null && !stack.containsKey(tClass.getName())) {
            stack.put(tClass.getName(), instance);
        }

        return instance;
    }
}
